﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Workflow.BusinessFacade;
using Honestysoft.Workflow.Model;
using Honestysoft.BaseObject;
using Honestysoft.Baseframework.WebUI;

namespace Honestysoft.Financing.WebUI.Module.WorkflowAcc
{
    public partial class WFOpinionEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            QueryParameters query = new QueryParameters();
            OrderParameters order = new OrderParameters();
            order.Add("TranTime");
            query.Add("DataIDArr", Request.QueryString["id"], QueryParameters.OperatorType.Equal);
            List<WF_ActTransact> lsOpinion = new BaseBusinessLogic<WF_ActTransact>().GetEntitys(query, order);
            rptList.DataSource = lsOpinion;
            rptList.DataBind();
            if (lsOpinion == null || lsOpinion.Count == 0)
            {
                btnSave.Enabled = false;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                BaseBusinessLogic<WF_ActTransact> logic = new BaseBusinessLogic<WF_ActTransact>();
                QueryParameters query = new QueryParameters();
                query.Add("DataIDArr", Request.QueryString["id"], QueryParameters.OperatorType.Equal);
                List<WF_ActTransact> lsOpinion = logic.GetEntitys(query);
                HiddenField hidID = null;
                TextBox txtOpinion = null;
                foreach (RepeaterItem ri in rptList.Items)
                {
                    hidID = ri.FindControl("hidID") as HiddenField;
                    txtOpinion = ri.FindControl("txtOpinion") as TextBox;
                    foreach (WF_ActTransact at in lsOpinion)
                    {
                        if (at.ID == hidID.Value)
                        {
                            at.Opinion = txtOpinion.Text;
                            break;
                        }
                    }
                }
                logic.UpdateEntitys(lsOpinion);
                ScriptHelper.Window.AlertClose("修改意见成功！");
            }
            catch (Exception ex)
            {
                Honestysoft.BaseLibrary.ExceptionHandling.ExceptionHelper.ExceptionDistribute(ex, false);
                ScriptHelper.Window.AlertClose("修改意见失败！系统发生未知错误！");
            }
        }
    }
}